package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "菜品相关接口")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    DishService dishService;
        @PostMapping
        @ApiOperation("增加菜品")
        public Result save(@RequestBody DishDTO dishDTO)
        {
            log.info("新增菜品 {}" ,dishDTO);
            dishService.addDish(dishDTO);
        return Result.success();
        }
        @PostMapping("/status/{status}")
        public Result dishStatus(@PathVariable("status") String status,@RequestParam("id") Integer dishId)
        {
            log.info("起售停售功能 ");
            dishService.status(status,dishId);
            return Result.success();
        }
         //根据分类查询菜品
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dto)
    {
        log.info("菜品分页查询:{}",dto);
         PageResult pageResult =  dishService.pageQuery(dto);
        return Result.success(pageResult);
    }
    @ApiOperation("批量删除")
    @DeleteMapping("")
    public Result  deleteDish(@RequestParam List<Long> ids)
    {
        log.info("批量删除");
        dishService.deleteDish(ids);
        return Result.success();
    }
    @GetMapping ("/{id}")
    @ApiOperation("根据ID查询菜品")
    public Result<DishVO> getById(@PathVariable Long id)
    {
        log.info("根据ID查询菜品{}",id);
       DishVO dishVO =  dishService.selectDishById(id);
        return Result.success(dishVO);
    }

    @ApiOperation("修改菜品")
    @PutMapping
    public Result update (@RequestBody DishDTO dishDTO)
    {
        log.info("修改菜品{}",dishDTO);
        dishService.update(dishDTO);
        return Result.success();
    }
    @ApiOperation("根据分类ID查询菜品")
    @GetMapping("/list")
    public Result< List<Dish>> selectList(@RequestParam(required = false) Long categoryId)
    {
        log.info("根据分类ID查询菜品{}",categoryId);
        List<Dish> list = dishService.selectList(categoryId);
        return Result.success(list);
    }
}
